home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / fsavx20d / FRMCLIEN.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-04-03  |  6.2 KB  |  190 lines

  1. VERSION 5.00
  2. Begin VB.Form frmClient 
  3.    Caption         =   "Client"
  4.    ClientHeight    =   3045
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   5865
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3045
  10.    ScaleWidth      =   5865
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command1 
  13.       Caption         =   "&Client"
  14.       Height          =   345
  15.       Left            =   4530
  16.       TabIndex        =   6
  17.       Top             =   480
  18.       Width           =   1215
  19.    End
  20.    Begin VB.TextBox Text1 
  21.       Height          =   435
  22.       Left            =   1950
  23.       TabIndex        =   0
  24.       Top             =   1500
  25.       Width           =   2235
  26.    End
  27.    Begin VB.CommandButton cmdOK 
  28.       Caption         =   "OK"
  29.       Height          =   315
  30.       Left            =   4530
  31.       TabIndex        =   1
  32.       Top             =   90
  33.       Width           =   1200
  34.    End
  35.    Begin VB.Label Label4 
  36.       Height          =   1485
  37.       Left            =   150
  38.       TabIndex        =   5
  39.       Top             =   1500
  40.       Width           =   1635
  41.    End
  42.    Begin VB.Label Label3 
  43.       Caption         =   "Data saved by the server:"
  44.       Height          =   765
  45.       Left            =   150
  46.       TabIndex        =   4
  47.       Top             =   180
  48.       Width           =   1485
  49.    End
  50.    Begin VB.Label Label2 
  51.       BorderStyle     =   1  'Fixed Single
  52.       Height          =   345
  53.       Left            =   1950
  54.       TabIndex        =   3
  55.       Top             =   600
  56.       Width           =   2205
  57.    End
  58.    Begin VB.Label Label1 
  59.       BorderStyle     =   1  'Fixed Single
  60.       Height          =   315
  61.       Left            =   1950
  62.       TabIndex        =   2
  63.       Top             =   180
  64.       Width           =   2205
  65.    End
  66. Attribute VB_Name = "frmClient"
  67. Attribute VB_GlobalNameSpace = False
  68. Attribute VB_Creatable = False
  69. Attribute VB_PredeclaredId = True
  70. Attribute VB_Exposed = False
  71. ' *******************************************************************
  72. ' ** This example was created by Fishhead Software, 1998-1999
  73. ' *******************************************************************
  74. Option Explicit
  75. Private m_Share As fsShare
  76. Private m_Handle As Long
  77. 'Private WithEvents m_Events As fsEvents  ' ** Needed only if want to receive messages
  78. Private Sub cmdOK_Click()
  79.     Unload Me
  80. End Sub
  81. Private Sub Command1_Click()
  82.     If GetServer <> fsSHHNoServerHandle Then
  83.         
  84.         ' ** Ensure the next client will attach
  85.         ' ** to the same server;
  86.         m_Share.SetDefaultServer
  87.         If UCase$(App.EXEName) = "CLIENT VB5" Then
  88.             Shell "client vb5.exe", vbNormalFocus
  89.         Else
  90.             Shell "client vb6.exe", vbNormalFocus
  91.         End If
  92.         
  93.     End If
  94. End Sub
  95. Private Sub Form_Initialize()
  96.     Set m_Share = New fsShare
  97.    ' Set m_Events = m_Share.fsEvents  ' Only needed if we want the messages
  98.     ' ** Coonect to the server as client;
  99.     m_Handle = m_Share.ConnectClient("my server", "my client")
  100. End Sub
  101. Private Sub Form_Load()
  102.     On Error Resume Next
  103.     Dim f As Object
  104.     Dim s As Variant
  105.     Dim i As Long
  106.      
  107.     If m_Share.GetServerHandle <> fsSHHNoServerHandle Then
  108.         ' ** Determine if the server saved its width and height;
  109.         i = m_Share.GetIndex("pos")
  110.         If i Then
  111.             ' ** It did, now position the client accordingly.
  112.             ' ** Returns an array, s(1) = Width and s(2) = Height;
  113.             s = m_Share.GetDataByIndex(i)
  114.             Me.Move s(1), s(2)
  115.         End If
  116.         
  117.         ' ** Get the data saved by the server;
  118.         Label1.Caption = m_Share.GetData("Company")
  119.         Label2.Caption = m_Share.GetData("Product")
  120.         
  121.         ' ** You can get saved objects;
  122.         Set f = m_Share.GetObject("server form")
  123.         
  124.     End If
  125.     Label4.Caption = "Edit me.  Add some text in the text box and watch how the server gets updated."
  126. End Sub
  127. Private Sub Form_Terminate()
  128.     ' ** Remove the connection to free up the data;
  129.     m_Share.DisconnectClient
  130. End Sub
  131. Private Sub Text1_Change()
  132.     Dim Handle As Long
  133.       
  134.     ' ** Verify if the client is attached to a server;
  135.     Handle = GetServer
  136.     If Handle <> fsSHHNoServerHandle Then
  137.         ' ** Echo the changes to the server text
  138.         ' ** window using our own defined message;
  139.         Call m_Share.FireDataMessage(Handle, fsSHFMUser + 1, Text1.Text)
  140.     End If
  141. End Sub
  142. ' **********************************************
  143. ' ** This routine will return the server handle
  144. ' ** and load the server if it is not present;
  145. ' **********************************************
  146. Private Function GetServer() As Long
  147.     On Error GoTo ErrorHandler
  148.     Dim ServerHandle As Long
  149.     Dim t As Long
  150.     ' ** Gets the server handle or returns
  151.     ' ** no handle;
  152.     ServerHandle = m_Share.GetServerHandle
  153.     If ServerHandle = fsSHHNoServerHandle Then
  154.         
  155.         ' ** Start the server;
  156.         Shell "Server.exe", vbNormalNoFocus
  157.         
  158.         ' ** Wait until server handle gets set;
  159.         Do
  160.             DoEvents
  161.             ServerHandle = m_Share.GetServerHandle
  162.         Loop While ServerHandle = fsSHHNoServerHandle
  163.         
  164. Retry:
  165.         ' ** Keep on retrying until server is fully loaded;
  166.         If ServerHandle <> fsSHHNoServerHandle Then
  167.             ' *********************************************
  168.             ' ** These commands will error out if the
  169.             ' ** server has not save them in its form load;
  170.             ' *********************************************
  171.             Label1.Caption = m_Share.GetData("Company")
  172.             Label2.Caption = m_Share.GetData("Product")
  173.         End If
  174.         
  175.     End If
  176. ExitFunc:
  177.     GetServer = ServerHandle
  178.     Exit Function
  179. ErrorHandler:
  180.     ' ****************************************
  181.     ' ** Keep on trying until item is set,
  182.     ' ** otherwise some other error occurred;
  183.     ' ****************************************
  184.     If Err.Number = fsSHErrItemNotFound Then
  185.         Resume Retry
  186.     Else
  187.         Resume ExitFunc
  188.     End If
  189. End Function
  190.